<?php

namespace app\admin\logic;

use app\common\model\Branch;
use app\common\model\User;
use app\common\model\Work;

/**
 * Class CarLogic
 * @package app\admin\logic
 *
 * 车辆管理
 * 车辆登陆
 */
class BranchLogic
{
    function findAll()
    {
        return Branch::all();
    }

    function findById($id)
    {
        return Branch::get($id);
    }

    function findByUserId($id)
    {
        $branch_id = User::get($id)->value("branch_id");
        return $this->findById($branch_id);
    }

    function findByWorkId($id)
    {
        $branch_id = Work::get($id)->value("server_type");
        return $this->findById($branch_id);
    }

    public function del($id)
    {
        return Branch::get($id)->delete();
    }

    public function andAndUpdate($data)
    {
        if (!empty($data['id'])) {
            return model('branch')->data($data)->allowField(true)->isUpdate(true)->save();
        } else {
            $data["enable"] = true;
            return model('branch')->data($data)->allowField(true)->save();
        }
    }
}
